<template>
    <div class="game">
      <!-- 顶部区域 -->
      <div class="header-section">
        <!-- 整合颜色选择器和返回按钮 -->
        <div class="color-selector-with-back">
          <!-- 顶部颜色选择器 -->
          <ColorSelector class="color-selector" />
          
          <!-- 返回主页按钮 -->
          <button class="back-to-home" @click="backToHome">
            ← 返回主页
          </button>
        </div>
      </div>
      
      <!-- 主内容区域 -->
      <div class="main-content">
        <!-- 左侧：玩家信息区域（整合倒计时和排名） -->
        <div class="left-panel">
          <div class="player-info-container">
            <GameTimer class="timer" />
            <PlayerList class="players" />
          </div>
        </div>
        
        <!-- 中间：画布 -->
        <GameCanvas class="canvas" />
        
        <!-- 右侧：实时统计 -->
        <AreaStats class="stats" />
      </div>
    </div>
  </template>
  
  <script setup>
  import GameCanvas  from '@/components/GameCanvas.vue'
  import PlayerList  from '@/components/PlayerList.vue'
  import GameTimer   from '@/components/GameTimer.vue'
  import AreaStats   from '@/components/AreaStats.vue'
  import ColorSelector from '@/components/ColorSelector.vue'
  import { useRoomStore } from '@/stores/room'
import { useRouter } from 'vue-router'

const roomStore = useRoomStore()
const router = useRouter()

const backToHome = () => {
  roomStore.leaveRoom()
  router.push('/')
}
  </script>
  
  <style scoped>
/* 主容器 */
.game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  gap: 16px;
  padding: 12px;
  background: var(--bg);
  background-image: var(--bg-gradient);
  overflow: hidden;
}

/* 顶部区域 */
.header-section {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

/* 整合的颜色选择器和返回按钮容器 - 铺满整个顶部 */
.color-selector-with-back {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  background: var(--surface);
  background-image: linear-gradient(145deg, rgba(30, 41, 59, 0.9) 0%, rgba(51, 65, 85, 0.9) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 8px 20px;
}

/* 返回主页按钮 */
.back-to-home {
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 6px;
}

.back-to-home:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--primary);
  transform: translateY(-2px);
}

.back-to-home::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%);
  transition: width 0.4s, height 0.4s;
}

.back-to-home:hover::before {
    width: 300px;
    height: 300px;
  }

  /* 调整颜色选择器样式以适应整合布局 */
  .color-selector .color-selector-container {
    background: transparent !important;
    background-image: none !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    padding: 0 !important;
  }

  .color-selector .color-selector-container:hover {
    box-shadow: none !important;
  }

/* 主内容区域 - 左中右并列弹性布局 */
.main-content {
  display: flex;
  flex: 1;
  gap: 12px;
  min-height: 0;
  width: 100%;
}

/* 左侧面板 */
.left-panel {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* 玩家信息整合容器 */
.player-info-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
  min-height: 0;
  background: var(--surface);
  background-image: linear-gradient(145deg, rgba(30, 41, 59, 0.9) 0%, rgba(51, 65, 85, 0.9) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.player-info-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
}

.player-info-container::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-light) 0%, var(--primary-dark) 100%);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* 画布区域 */
.canvas {
  flex: 1;
  min-width: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--primary-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  padding: 0;
  margin: 0;
}

/* 右侧统计区域 */
.stats {
  flex: 0 0 220px;
  height: 100%;
}

/* 卡片通用样式 */
.timer, .stats, .players {
  background: var(--surface);
  background-image: linear-gradient(145deg, var(--surface) 0%, var(--surface-hover) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: all 0.3s ease-in-out;
  padding: 0;
  overflow: hidden;
  position: relative;
}

.timer:hover, .stats:hover, .players:hover {
  box-shadow: var(--shadow-lg), 0 0 20px rgba(59, 130, 246, 0.15);
  transform: translateY(-2px);
  border-color: var(--primary-light);
}

/* 卡片底部边框装饰 */
.timer::after, .stats::after, .players::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-light) 0%, var(--primary-dark) 100%);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* 左侧面板样式 - 整合后的样式 */
.player-info-container .timer {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: bold;
  color: var(--text-primary);
  position: relative;
  overflow: hidden;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.player-info-container .timer::after {
  content: '游戏倒计时';
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: normal;
}

.player-info-container .players {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

/* 移除卡片通用样式中的底部装饰，因为已在容器上统一定义 */
.player-info-container .timer::after,
.player-info-container .players::after {
  display: none;
}

/* 统计区域样式 */
.stats {
  height: 100%;
  overflow: hidden;
}

/* 画布样式增强 */
.canvas {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: white;
  border: 3px solid var(--primary-light);
  box-shadow: var(--shadow-lg), 0 0 30px rgba(59, 130, 246, 0.1);
  position: relative;
  transition: all 0.3s ease-in-out;
  width: 100%;
}

.canvas:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(59, 130, 246, 0.2);
}

/* 画布容器背景装饰 */
.canvas::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.05) 0%, transparent 70%);
  pointer-events: none;
  z-index: 10;
}
</style>